package com.wxapp.dispatch.service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.dispatch.api.pojo.vo.dispatch.QDispatchAddVo;
import com.wxapp.dispatch.api.pojo.vo.dispatch.QDispatchPageVo;
import com.wxapp.dispatch.api.pojo.vo.dispatch.QDispatchUpdateVo;
import com.wxapp.dispatch.api.pojo.vm.dispatch.PDispatchDetailVm;
import com.wxapp.dispatch.api.pojo.vm.dispatch.PDispatchPageVm;
import com.wxapp.dispatch.service.service.DispatchService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.*;

/**
 * @author lgl
 * @Description 调度管理
 * @Datetime 2023/5/26 17:58
 * @Modified By
 */
@RestController
@Tag(name = "调度管理")
@RequestMapping("dis")
@RequiredArgsConstructor
public class DispatchController extends IBaseController {
    private final DispatchService dispatchService;

    @PostMapping("page")
    @Operation(summary ="定时任务分页")
    public ResultVm<Page<PDispatchPageVm>> page(@RequestBody QDispatchPageVo vm) {
        return dispatchService.page(vm);
    }

    @GetMapping("detail/{id}")
    @Operation(summary ="详情")
    public ResultVm<PDispatchDetailVm> detail(@PathVariable String id) {
        return dispatchService.detail(id);
    }

    @PostMapping("add")
    @Operation(summary ="添加")
    public ResultVm<String> add(@RequestBody QDispatchAddVo vm) throws SchedulerException {
        return dispatchService.add(vm);
    }

    @PutMapping("update")
    @Operation(summary ="更新")
    public ResultVm<String> update(@RequestBody QDispatchUpdateVo vm) throws SchedulerException {
        return dispatchService.update(vm);
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary ="删除定时任务")
    public ResultVm<String> delete(@PathVariable String id) {
        return dispatchService.delete(id);
    }


    @PutMapping("pauseOrRes/{id}")
    @Operation(summary ="暂停或恢复执行定时任务")
    public ResultVm<String> pauseOrRes(@PathVariable String id, @RequestBody Boolean isPause) throws SchedulerException {
        return dispatchService.pauseOrRes(id, isPause);
    }
}
